package com.ficv.tucanalmovil.dominio;

import javax.persistence.EntityManager;
import javax.persistence.ManyToOne;
import javax.persistence.TypedQuery;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@XmlRootElement(name = "aviso")
@RooJpaActiveRecord(finders = { "findAvisosesByTextoIsNull", "findAvisosesByEmpresa" })
public class Avisos {

    public static final String TYPE_IN = "IN";

    public static final String TYPE_OUT = "OUT";

    private String texto;

    private String hora;

    @XmlTransient
    public Empresa getEmpresa() {
        return this.empresa;
    }
    
    @ManyToOne
    private Empresa empresa;

    private String tipo;

    public static TypedQuery<Avisos> findAvisosesByDeviceAndEmpresaAndIdGreaterThan(Device dev, Empresa emp, Long id) {
        EntityManager em = Avisos.entityManager();        
        TypedQuery<Avisos> q = em.createQuery("SELECT a FROM Avisos AS a, Device AS d WHERE a.id>:id AND d=:dev AND a MEMBER OF d.avisos  AND a.empresa=:emp", Avisos.class);
        q.setParameter("emp", emp);
        q.setParameter("dev", dev);
        q.setParameter("id", id);
        return q;
    }


}
